import type { FilterItem, PageResult } from "../types/global";
import type {
  CourseSubmitTabItem,
  CourseItem,
  CourseSubmitCreateParams,
  CourseSubmitItem,
  CourseSubmitView,
  CourseView,
  CourseTrainingItem,
  CourseTrainingListItem,
  CourseSubmitListItem,
  CourseSubmitScoreItem,
  SimpleListItem,
} from "../types/aviation";
import http from "../utils/http";
import { useMemberStore } from "../store";
// 获取课程所有分类
export const postCourseCategory = () => {
  return http<FilterItem[]>({
    url: "CourseCategory/all",
    method: "POST",
  });
};

// 获取课程类型
export const postCourseType = () => {
  return http<FilterItem[]>({
    url: "CourseType/all",
    method: "POST",
  });
};

// 获取开课时间
export const postCourseTime = () => {
  return http<FilterItem[]>({
    url: "CourseTime/all",
    method: "POST",
  });
};

// 获取开课地点
export const postCourseAddress = () => {
  return http<FilterItem[]>({
    url: "CourseAddress/all",
    method: "POST",
  });
};

// 获取课程标签
export const postCourseTag = () => {
  return http<FilterItem[]>({
    url: "CourseTag/all",
    method: "POST",
  });
};

// 发布课程列表
export const postCouseList = (data) => {
  return http<PageResult<CourseItem[]>>({
    url: "Course/index",
    method: "POST",
    data,
  });
};

// 课程详情
export const postCourseDetail = (id: number) => {
  return http<CourseView>({
    url: "Course/view",
    method: "POST",
    data: {
      id,
    },
  });
};

// 课程申请报名
export const postCourseApply = (data: CourseSubmitCreateParams) => {
  return http<CourseView>({
    url: "CourseSubmit/create",
    method: "POST",
    data,
  });
};

// 我的报名
export const postCourseSubmit = (data) => {
  return http<PageResult<CourseSubmitItem[]>>({
    url: "CourseSubmit/index",
    method: "POST",
    data,
  });
};

// 报名详情
export const postCourseSubmitView = (id: number) => {
  return http<CourseSubmitView>({
    url: "CourseSubmit/view",
    method: "POST",
    data: {
      id,
    },
  });
};

// 我的报名tab
export const postCourseSubmitTab = () => {
  return http<CourseSubmitTabItem[]>({
    url: "CourseSubmit/course_submit_tab",
    method: "POST",
  });
};

// 课程分类培训流程（任务头像那里流程变化）
export const postTraining = (course_id: number) => {
  return http<CourseTrainingItem[]>({
    url: "CourseTraining/all",
    method: "POST",
    data: {
      course_id,
    },
  });
};

// 培训流程下自定义选项内容
export const postTrainingList = (
  course_training_id: number,
  course_id: number
) => {
  return http<CourseTrainingListItem[]>({
    url: "CourseTrainingList/all",
    method: "POST",
    data: {
      course_training_id,
      course_id,
    },
  });
};

// 培训大纲列表
export const postCourseSubmitList = (data) => {
  return http<CourseSubmitListItem[]>({
    url: "CourseSubmit/course_submit_list",
    method: "POST",
    data,
  });
};

// 培训大纲分数
export const postCourseSubmitScoreList = (_data) => {
  const { profile } = useMemberStore();
  return http<CourseSubmitScoreItem>({
    url: "ProfessionScore/view",
    method: "POST",
    data: {
      course_id: _data.course_id,
      member_id: profile!.id,
    },
  });
};

// 新-培训大纲分数
export const postNewCourseSubmitScoreList = (course_id: number) => {
  const { profile } = useMemberStore();
  return http<CourseSubmitScoreItem[]>({
    url: "ProfessionScore/view",
    method: "GET",
    data: {
      course_id,
      member_id: profile!.id,
    },
  });
};

// 个人中心-成绩
export const postPersonalScoreList = () => {
  const { profile } = useMemberStore();
  return http<PageResult<any[]>>({
    url: "ProfessionScore/index",
    method: "POST",
    data: {
      member_id: profile!.id,
    },
  });
};

// 常规课程
export const postCourseSimpleList = (data) => {
  return http<PageResult<SimpleListItem[]>>({
    url: "CourseSimple/index",
    method: "POST",
    data,
  });
};

// 常规课程
export const postCourseSimpleSubmit = (data) => {
  return http<any>({
    url: "CourseSimpleSubmit/create",
    method: "POST",
    data,
  });
};
